package com.zhangjie.serviceorder.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * 自动生成代码工具类
 * @Auther: zj
 * @Date: 2024/2/26 - 02 - 26 - 11:39
 * @Description: com.zhangjie.servicedriveruser.generator
 * @version: 1.0
 */
public class MysqlGenerator {

    public static void main(String[] args) {

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/service-order?characterEncoding=utf-8&serverTimezone=GMT%2B8",
                "root","root")
                // author作者，fileOverride覆盖掉原来已经有的，outputDir输出目录
                .globalConfig(builder -> {
                    builder.author("张杰").fileOverride().outputDir("D:\\myProject\\idea-workspace\\online-taxi-public\\service-order\\src\\main\\java");
                })
                // 设置包的一些属性，parent父包，pathInfo传入一个map指定mapper文件生成路径
                .packageConfig(builder -> {
                    builder.parent("com.zhangjie.serviceorder").pathInfo(Collections.singletonMap(OutputFile.mapperXml,
                            "D:\\myProject\\idea-workspace\\online-taxi-public\\service-order\\src\\main\\java\\com\\zhangjie\\serviceorder\\mapper"));
                })
                // 设置一些生成的策略，addInclude表名，addTablePrefix可以过滤表的前缀
                .strategyConfig(builder -> {
                    builder.addInclude("order_info");

                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
